package com.dhcc.core.config.properties;

import java.io.File;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.DependsOn;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import com.dhcc.core.framework.util.CommonUtil;
import com.dhcc.core.framework.util.SpringContextHolder;

/**
 * Sys项目配置
 *
 * @ClassName: SysProperties
 * @Description: 描述
 * @author: cyf
 * @date: 2018年1月2日 上午9:41:42
 */
@Component
@Order(value=1)
@ConfigurationProperties(prefix = SysProperties.PREFIX)
@DependsOn("springContextHolder")
public class SysProperties {

    public static final String PREFIX = "sys";

    public static final String FILE_UPLOAD = "file_upload";

    public static SysProperties me() {
        return SpringContextHolder.getBean(SysProperties.class);
    }

    private String sysEnName;

    private String sysHome;
    
    private String hospitalCode;

    private String sysFullName;

    private String orgFullName;

    private Boolean kaptchaOpen = false;

    private Boolean swaggerOpen = false;

    private Integer fileUploadMaxSize;
    
    private String dhcHisUserName;
    private String dhcHisPasword;
    private String dhcHisCacheIp;
    private String dhcHisCachePath;
    private String sdsServerIp;
    private String hospitalName;
    

    private Boolean redisOpen = false; // 是否启用redis

    private Integer sessionInvalidateTime = 30 * 60; // session 失效时间（默认为30分钟
                                                     // 单位：秒）

    private Integer sessionValidationInterval = 15 * 60; // session
                                                         // 验证失效时间（默认为15分钟
                                                         // 单位：秒）
    private int maxSession = 1; // 同一个帐号最大会话数 默认1

    private int maxRetryLimit = 0; // 最大登录重试次数 默认0不限制

    private int retryFreezeTime = 600; // 冻结时间 单位：秒

    private String frontPath;

    private String backendPath;

    private String frontAuthPath;

    private String apiPath;

    private String wsPath;

    private String frontLoginPage;

    private String backendLoginPage;

    private String backendRoleNames;

    private String demoAccount;

    private String authType;

    private String[] xssAllowedUrl;

    private String[] refererAllowedHost; //被允许的来源

    private Boolean resetPassOpen;

    private int resetPassVcodeTimeout;

    public String getFileUploadPath() {

        String fileUploadPath = this.getSysHome() + FILE_UPLOAD;
        // 判断有没有结尾符,没有得加上
        if (!fileUploadPath.endsWith(File.separator)) {
            fileUploadPath = fileUploadPath + File.separator;
        }
        // 判断目录存不存在,不存在得加上
        File file = new File(fileUploadPath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return fileUploadPath;
    }

    public Integer getFileUploadMaxSize() {
        if (CommonUtil.isEmpty(fileUploadMaxSize)) {
            return 10 * 1024 * 1024;
        } else {
            return fileUploadMaxSize;
        }
    }


    // beetl的模板资源位置
    public String getBeetlViewPath() {
        return getSysHome()+"view"+ File.separator;
    }

    // 静态资源位置
    public String getStaticPath() {
        return getSysHome()+"static"+ File.separator;
    }

    public String getSysHome() {
        // 判断有没有结尾符,没有得加上
        if (!sysHome.endsWith(File.separator)) {
            sysHome = sysHome + File.separator;
        }
        return sysHome;
    }

    public void setFileUploadMaxSize(Integer fileUploadMaxSize) {
        this.fileUploadMaxSize = fileUploadMaxSize;
    }

    public Boolean getKaptchaOpen() {
        return kaptchaOpen;
    }

    public void setKaptchaOpen(Boolean kaptchaOpen) {
        this.kaptchaOpen = kaptchaOpen;
    }

    public Boolean getSwaggerOpen() {
        return swaggerOpen;
    }

    public void setSwaggerOpen(Boolean swaggerOpen) {
        this.swaggerOpen = swaggerOpen;
    }

    public Integer getSessionInvalidateTime() {
        return sessionInvalidateTime;
    }

    public void setSessionInvalidateTime(Integer sessionInvalidateTime) {
        this.sessionInvalidateTime = sessionInvalidateTime;
    }

    public Integer getSessionValidationInterval() {
        return sessionValidationInterval;
    }

    public void setSessionValidationInterval(Integer sessionValidationInterval) {
        this.sessionValidationInterval = sessionValidationInterval;
    }

    public String getFrontPath() {
        return frontPath;
    }

    public void setFrontPath(String frontPath) {
        this.frontPath = frontPath;
    }

    public String getBackendPath() {
        return backendPath;
    }

    public void setBackendPath(String backendPath) {
        this.backendPath = backendPath;
    }

    public String getApiPath() {
        return apiPath;
    }

    public void setApiPath(String apiPath) {
        this.apiPath = apiPath;
    }

    public String getFrontLoginPage() {
        return frontLoginPage;
    }

    public void setFrontLoginPage(String frontLoginPage) {
        this.frontLoginPage = frontLoginPage;
    }

    public String getBackendLoginPage() {
        return backendLoginPage;
    }

    public void setBackendLoginPage(String backendLoginPage) {
        this.backendLoginPage = backendLoginPage;
    }

    public String getWsPath() {
        return wsPath;
    }

    public void setWsPath(String wsPath) {
        this.wsPath = wsPath;
    }

    public String getBackendRoleNames() {
        return backendRoleNames;
    }

    public void setBackendRoleNames(String backendRoleNames) {
        this.backendRoleNames = backendRoleNames;
    }

    public String getFrontAuthPath() {
        return this.frontPath + frontAuthPath;
    }

    public void setFrontAuthPath(String frontAuthPath) {
        this.frontAuthPath = frontAuthPath;
    }

    public void setSysHome(String sysHome) {
        this.sysHome = sysHome;
    }

    public Boolean getRedisOpen() {
        return redisOpen;
    }

    public void setRedisOpen(Boolean redisOpen) {
        this.redisOpen = redisOpen;
    }

    public int getMaxSession() {
        return maxSession;
    }

    public void setMaxSession(int maxSession) {
        this.maxSession = maxSession;
    }

    public String getDemoAccount() {
        return demoAccount;
    }

    public void setDemoAccount(String demoAccount) {
        this.demoAccount = demoAccount;
    }

    public String[] getXssAllowedUrl() {
        return xssAllowedUrl;
    }

    public void setXssAllowedUrl(String[] xssAllowedUrl) {
        this.xssAllowedUrl = xssAllowedUrl;
    }

    public String getSysFullName() {
        return sysFullName;
    }

    public void setSysFullName(String sysFullName) {
        this.sysFullName = sysFullName;
    }

    public String getOrgFullName() {
        return orgFullName;
    }

    public void setOrgFullName(String orgFullName) {
        this.orgFullName = orgFullName;
    }

    public String getSessionCookieName() {
        return getSysEnName()+"_session_id";
    }

    public String getRememberMeCookieName() {
        return getSysEnName()+"_remember_me";
    }

    public String getSysEnName() {
        return CommonUtil.isNotEmpty(sysEnName)?sysEnName:"medical_sds";
    }

    public void setSysEnName(String sysEnName) {
        this.sysEnName = sysEnName;
    }

    public String getAuthType() {
        return authType;
    }

    public void setAuthType(String authType) {
        this.authType = authType;
    }

    public String[] getRefererAllowedHost() {
        return refererAllowedHost;
    }

    public void setRefererAllowedHost(String[] refererAllowedHost) {
        this.refererAllowedHost = refererAllowedHost;
    }

    public int getMaxRetryLimit() {
        return maxRetryLimit;
    }

    public void setMaxRetryLimit(int maxRetryLimit) {
        this.maxRetryLimit = maxRetryLimit;
    }

    public int getRetryFreezeTime() {
        return retryFreezeTime;
    }

    public void setRetryFreezeTime(int retryFreezeTime) {
        this.retryFreezeTime = retryFreezeTime;
    }

    /**
     * @return the resetPassOpen
     */
    public Boolean getResetPassOpen() {
        return resetPassOpen;
    }

    /**
     * @param resetPassOpen the resetPassOpen to set
     */
    public void setResetPassOpen(Boolean resetPassOpen) {
        this.resetPassOpen = resetPassOpen;
    }

    /**
     * @return the resetPassVcodeTimeout
     */
    public int getResetPassVcodeTimeout() {
        return resetPassVcodeTimeout;
    }

    /**
     * @param resetPassVcodeTimeout the resetPassVcodeTimeout to set
     */
    public void setResetPassVcodeTimeout(int resetPassVcodeTimeout) {
        this.resetPassVcodeTimeout = resetPassVcodeTimeout;
    }

	/**  
	 * hospitalCode 
	 * return  the hospitalCode   
	 */
	public String getHospitalCode() {
		return hospitalCode;
	}

	/**  
	 * hospitalCode 
	 * param hospitalCode the hospitalCode to set   
	 */
	public void setHospitalCode(String hospitalCode) {
		this.hospitalCode = hospitalCode;
	}

	public String getDhcHisUserName() {
		return dhcHisUserName;
	}

	public String getDhcHisPasword() {
		return dhcHisPasword;
	}

	public void setDhcHisUserName(String dhcHisUserName) {
		this.dhcHisUserName = dhcHisUserName;
	}

	public void setDhcHisPasword(String dhcHisPasword) {
		this.dhcHisPasword = dhcHisPasword;
	}

	public String getDhcHisCacheIp() {
		return dhcHisCacheIp;
	}

	public void setDhcHisCacheIp(String dhcHisCacheIp) {
		this.dhcHisCacheIp = dhcHisCacheIp;
	}

	public String getDhcHisCachePath() {
		return dhcHisCachePath;
	}

	public void setDhcHisCachePath(String dhcHisCachePath) {
		this.dhcHisCachePath = dhcHisCachePath;
	}

    public String getSdsServerIp() {
        return sdsServerIp;
    }

    public void setSdsServerIp(String sdsServerIp) {
        this.sdsServerIp = sdsServerIp;
    }

	public String getHospitalName() {
		return hospitalName;
	}

	public void setHospitalName(String hospitalName) {
		this.hospitalName = hospitalName;
	}
	
	
    
}
